package anpham.example;

import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

	private static final String DEBUG_TAG = "Debug";
	private Map<String, Button> list_bt;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		list_bt = new HashMap<String, Button>();
		list_bt.put("bt1", (Button) findViewById(R.id.bt1));
		list_bt.put("bt2", (Button) findViewById(R.id.bt2));
		list_bt.put("bt3", (Button) findViewById(R.id.bt3));
		list_bt.put("bt4", (Button) findViewById(R.id.bt4));
		list_bt.put("bt5", (Button) findViewById(R.id.bt5));
		
		list_bt.get("bt1").setOnClickListener( new ClickManage( list_bt.get("bt1")));

		for (Button b : list_bt.values()) {
			Log.d(DEBUG_TAG, "onCLick: " + b.getText());
			b.setOnClickListener(new ClickManage(b));
			
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	class ClickManage implements OnClickListener {
		private Button b;

		public ClickManage(Button b) {
			this.b = b;
		}

		@Override
		public void onClick(View v) {
			Log.d(DEBUG_TAG, "onCLick: " + b.getText());
		}
	}

}
